using System.Data.Objects;
using System.Web.Mvc;
using System.Web.Security;
using Microsoft.Practices.Unity;
using WRSManagementSystem.Controllers;
using WRSManagementSystem.DataAccess;
using WRSManagementSystem.DataAccess.Repositories;
using WRSManagementSystem.DomainModel.Repositories;
using WRSManagementSystem.DomainModel.Services;

namespace WRSManagementSystem
{
    public static class Bootstrapper
    {
        public static void ConfigureUnityContainer()
        {
            IUnityContainer container = new UnityContainer();

            // Registrations

            //repositories
            container.RegisterType<IProjectsRespoitory, ProjectsRepository>
                (new HttpContextLifetimeManager<IProjectsRespoitory>());

            container.RegisterType<IPeopleRepository, PeopleRepository>
                (new HttpContextLifetimeManager<IPeopleRepository>());

            container.RegisterType<ITasksRepository, TasksRepository>
                (new HttpContextLifetimeManager<ITasksRepository>());

            container.RegisterType<ObjectContext, WRSEntitiesContainer>
                (new HttpContextLifetimeManager<ITasksRepository>());

            container.RegisterType<IStoreItemsRepository, StoreItemRepository>
                (new HttpContextLifetimeManager<IStoreItemsRepository>());

            container.RegisterType<ITypeRepository, TypesRepository>
                (new HttpContextLifetimeManager<ITypeRepository>());

            container.RegisterType<IUnitsRepository, UnitsRepository>
                (new HttpContextLifetimeManager<IUnitsRepository>());


            //Entites DAO
            container.RegisterType<ObjectContext, WRSEntitiesContainer>
                (new HttpContextLifetimeManager<ObjectContext>())
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<WRSEntitiesContainer>(new InjectionConstructor());

            //domain services
            container.RegisterType<ITaskAssignmentService, TaskAssignmentService>
                (new HttpContextLifetimeManager<ITaskAssignmentService>());

            //Authentication Services
            container.RegisterType<IMembershipService, AccountMembershipService>
                (new HttpContextLifetimeManager<IMembershipService>());

            container.RegisterType<IFormsAuthenticationService, FormsAuthenticationService>
                (new HttpContextLifetimeManager<IFormsAuthenticationService>());

            container.RegisterInstance(Membership.Provider);


            ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory(container));
        }
    }
}